<template>
  <div id="usualgeometry"></div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'

const scene = new THREE.Scene()
/**
 * geometry 几何体
 * widthSegments 纵向分段数
 * heightSegments 横向分段数
 * depthSegments 深度分段数
 * widthSegments, heightSegments, depthSegments 默认值为1
 * wireframe 是否显示线框;
 * 想要实心并显示线框，需要设置两个材质，一个实心，一个线框
 */
const geometry = new THREE.BoxGeometry(10, 10, 10, 5, 5, 5);
const material = new THREE.MeshBasicMaterial(
  {
    color: '#2b7098',
    transparent: true,
    opacity: 0.8,
    wireframe: true
  }
)

const mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.set(0, 0, 20)

const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)

const animate = () => {
  requestAnimationFrame(animate)
  mesh.rotation.x += 0.01
  mesh.rotation.y += 0.01
  mesh.rotation.z += 0.01
  renderer.render(scene, camera)
}
onMounted(() => {
  new OrbitControls(camera, renderer.domElement)
  document.getElementById('usualgeometry').appendChild(renderer.domElement)
  animate()
})

window.onresize = () => {
  renderer.setSize(window.innerWidth, window.innerHeight)
  camera.aspect = window.innerWidth / window.innerHeight
  camera.updateProjectionMatrix()
}
</script>

<style>

</style>